﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ControlAccessUser.Presenter;
using ControlAccessUser.Model;

namespace ControlAccessUser.Tests
{
    [TestClass]
    public class LoginTest
    {
        MockLoginView vLoginView;
        PresenterLogin pLogin;
        
        [TestInitialize]
        public void initial()
        {
            vLoginView = new MockLoginView();
            pLogin = new PresenterLogin(vLoginView);
            ControlAccessUser.DataAccess.ControlAccessUserEntities.Instance.Users.Add(new User() { UserName = "gary", UserPassword = "123456" });
            ControlAccessUser.DataAccess.ControlAccessUserEntities.Instance.SaveChanges();
        }

        [TestCleanup]
        public void clean()
        {
            ControlAccessUser.DataAccess.ControlAccessUserEntities.Instance.LimpiarDB();
        }

        /// <summary>
        /// Verifica que el UserName y password existan y sean correctos
        /// </summary>
        [TestMethod]
        public void VerifyIfLoginIsCorrectly()
        {
            vLoginView.userEnterHisData();
            pLogin.CheckLogin();
            Assert.AreEqual(vLoginView.ErrorMessageValue, null);
            
        }

        /// <summary>
        /// Verifica que el UserName esta escrito correctamente (sin espacios)
        /// </summary>
        [TestMethod]
        public void CorrectValidateLogin()
        {
            vLoginView.EnterUserNameCorrect();
            pLogin.ValidateLogin();
            Assert.AreEqual("userNameSinEspacio", vLoginView.UserNameLoginChanged);
            Assert.AreEqual("userNameSinEspacio", vLoginView.UserNameLogin);
        }

        /// <summary>
        /// Verifica si el UserName no esta escrito correctamente(tiene espacios)
        /// </summary>
        [TestMethod]
        public void FailedValidateLogin()
        {
            vLoginView.EnterUserNameIncorrect();
            pLogin.ValidateLogin();
            Assert.AreEqual("", vLoginView.UserNameLoginChanged);
            Assert.AreEqual("", vLoginView.UserNameLogin);
        }

        /// <summary>
        /// Prueba que un usuario registre su ingreso exitosamente.
        /// </summary>
        [TestMethod]
        public void RegisterEntryOrExitLogin()
        {
            vLoginView.userEnterHisData();
            pLogin.RegisterEntryOrExit();
            Assert.AreEqual(null, vLoginView.ErrorMessageValue);
            Assert.AreEqual(Message.RegisterLoginSuccessfully, vLoginView.SystemMessage);
        }

        [TestMethod]
        public void RegisterEntryOrExitLogout()
        {
            vLoginView.userEnterHisData();
            pLogin.RegisterEntryOrExit();
            pLogin.RegisterEntryOrExit();
            Assert.AreEqual(null, vLoginView.ErrorMessageValue);
            Assert.AreEqual(Message.RegisterLogoutSuccessfully, vLoginView.SystemMessage);
        }
    }
}
